import { Component, Mixins } from 'vue-property-decorator'
import {
  handlerImport
} from '@/components/src/ImportExecl/index'

import { TableMixin } from './table'

@Component({
  components: {
  }
})
export class TableExtendImport extends Mixins(TableMixin) {
  /**
   * 导入Execl表到table数据
   *
   * @memberof TableMixin
   */
  public async tableImportExecl(componentOptions: Record<string, unknown>, extra?: Record<string, string>) {
    if (!this.tableApi.import) {
      throw new Error('未设置导入接口')
    }
    const fileds = this.columns
        .filter((column: ITable.IColumn) => (
          !column.form ||
          (
            typeof column.form.isExport !== 'undefined'
              ? column.form.isExport
              : (typeof column.form.isShowList === 'undefined' || column.form.isShowList))
          )
        )
        // .map(column => column.children || column)
        // .flat()
        .filter(column => column.key && column.key !== 'action')
    handlerImport(fileds, this.tableApi.import, componentOptions, extra)
  }
}
